$(function(){
	//获取URL参数显示对应的修改项
	var type = _mm.getUrlParam('type') || 'default',
		$element = $('.' + type + '-success');
		if(type === "payment"){
			var orderNumber  = _mm.getUrlParam('orderNumber');
			var $orderNumber = $element.find('.order-number');
			$orderNumber.attr('href',$orderNumber.attr('href')+orderNumber);
		}
	// 显示对应的提示元素
	$element.show();

	datetime('beginTime1');
	datetime('endTime2');
	datetime('seekHelpTime');
	datetime2('beginTime');
	datetime2('endTime');
})
var _mm = {
    // 获取url参数
    getUrlParam : function(name){
        var reg     = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
        var result  = window.location.search.substr(1).match(reg);
        return result ? decodeURIComponent(result[2]) : null;
    }
};
exports = _mm;
//首页底部按钮
function showMove(id){
	var display = $("."+id).css('display');
	if(display != 'block'){
		$('.hideContent').hide();
		$("."+id).toggle("slow");
	}else{
		$("."+id).hide();
	}
	
}
function myActicity(id){
	$(".selectLine").removeClass('selectLine');
	if(id=='fq'){
		$("#fq").show();
		$("#cy").hide();
		$(".div-mya-d").addClass('selectLine');
	}else{
		$("#cy").show();
		$("#fq").hide();
		$(".div-mya-q").addClass('selectLine');
	}
}
//时间控件  年月日
function datetime(id){
	$("#"+id).datetimepicker({
        format: 'yyyy-mm-dd',
        minView:'month',
        language: 'zh-CN',
        autoclose:true
    }).on("click",function(){
        //$("#datetimeStart").datetimepicker("setEndDate",$("#datetimeEnd").val())
    });
}
//时间控件 年月
function datetime2(id){
	$("#"+id).datetimepicker({
        format: 'yyyy-mm',
        minView:'month',
        language: 'zh-CN',
        autoclose:true
    }).on("click",function(){
        //$("#datetimeStart").datetimepicker("setEndDate",$("#datetimeEnd").val())
    });
}


//时间控件 iosSelect 年月
function iosSelect(id){
    var showDateDom = $('#'+id);
    // 初始化时间
    var now = new Date();
    var nowYear = now.getFullYear();
    var nowMonth = now.getMonth() + 1;
    var nowMonth = nowMonth < 10 ? '0'+nowMonth :nowMonth
    showDateDom.attr('data-year', nowYear);
    showDateDom.attr('data-month', nowMonth);
    // 数据初始化
    function formatYear (nowYear) {
        var arr = [];
        for (var i = nowYear - 5; i <= nowYear + 5; i++) {
            arr.push({
                id: i + '',
                value: i //+ '年'
            });
        }
        return arr;
    }
    function formatMonth () {
        var arr = [];
        for (var i = 1; i <= 12; i++) {
            var i = i < 10 ? '0'+i :i 
            arr.push({
                id: i + '',
                value: i //+ '月'
            });
        }
        return arr;
    }
    var yearData = function(callback) {
        callback(formatYear(nowYear))
    }
    var monthData = function (year, callback) {
        callback(formatMonth());
    };
    showDateDom.bind('click', function () {
        var oneLevelId = showDateDom.attr('data-year');
        var twoLevelId = showDateDom.attr('data-month');
        var iosSelect = new IosSelect(2, 
            [yearData, monthData],
            {
                title: '时间选择',
                itemHeight: 35,
                itemShowCount: 9,
                oneLevelId: oneLevelId,
                twoLevelId: twoLevelId,
                callback: function (selectOneObj, selectTwoObj) {
                    showDateDom.attr('data-year', selectOneObj.id);
                    showDateDom.attr('data-month', selectTwoObj.id);
                    showDateDom.val(selectOneObj.value + '-' + selectTwoObj.value);
                }
        });
    });
}

//时间控件 iosSelect 年月日
function iosSelect2(id){
    var showDateDom = $('#'+id);
    // 初始化时间
    var now = new Date();
    var nowYear = now.getFullYear();
    var nowMonth = now.getMonth() + 1;
    var nowDate = now.getDate();
    var nowMonth = nowMonth < 10 ? '0'+nowMonth :nowMonth
    var nowDate = nowDate < 10 ? '0'+nowDate :nowDate 
    showDateDom.attr('data-year', nowYear);
    showDateDom.attr('data-month', nowMonth);
    showDateDom.attr('data-date', nowDate);
    // 数据初始化
    function formatYear (nowYear) {
        var arr = [];
        for (var i = nowYear - 5; i <= nowYear + 5; i++) {
            arr.push({
                id: i + '',
                value: i //+ '年'
            });
        }
        return arr;
    }
    function formatMonth () {
        var arr = [];
        for (var i = 1; i <= 12; i++) {
            var i = i < 10 ? '0'+i :i 
            arr.push({
                id: i + '',
                value: i //+ '月'
            });
        }
        return arr;
    }
    function formatDate (count) {
        var arr = [];
        for (var i = 1; i <= count; i++) {
             var i = i < 10 ? '0'+i :i 
            arr.push({
                id: i + '',
                value: i //+ '日'
            });
        }
        return arr;
    }
    var yearData = function(callback) {
        callback(formatYear(nowYear))
    }
    var monthData = function (year, callback) {
        callback(formatMonth());
    };
    var dateData = function (year, month, callback) {
        var month = parseInt(month);
        if (/^(1|3|5|7|8|10|12)$/.test(month)) {
            callback(formatDate(31));
        }
        else if (/^(4|6|9|11)$/.test(month)) {
            callback(formatDate(30));
        }
        else if (/^2$/.test(month)) {
            if (year % 4 === 0 && year % 100 !==0 || year % 400 === 0) {
                callback(formatDate(29));
            }
            else {
                callback(formatDate(28));
            }
        }
        else {
            throw new Error('month is illegal');
        }
    };
    showDateDom.bind('click', function () {
        var oneLevelId = showDateDom.attr('data-year');
        var twoLevelId = showDateDom.attr('data-month');
        var threeLevelId = showDateDom.attr('data-date');
        var iosSelect = new IosSelect(3, 
            [yearData, monthData, dateData],
            {
                title: '时间选择',
                itemHeight: 35,
                itemShowCount: 9,
                oneLevelId: oneLevelId,
                twoLevelId: twoLevelId,
                threeLevelId: threeLevelId,
                callback: function (selectOneObj, selectTwoObj, selectThreeObj) {
                    showDateDom.attr('data-year', selectOneObj.id);
                    showDateDom.attr('data-month', selectTwoObj.id);
                    showDateDom.attr('data-date', selectThreeObj.id);
                    showDateDom.val(selectOneObj.value + '-' + selectTwoObj.value + '-' + selectThreeObj.value);
                }
        });
    });
}

//时间控件 iosSelect 年月日时分
function iosSelect3(id){
    var showDateDom = $('#'+id);
    // 初始化时间
    var now = new Date();
    var nowYear = now.getFullYear();
    var nowMonth = now.getMonth() + 1;
    var nowDate = now.getDate();
    var hour = now.getHours();       //获取当前小时数(0-23)
    var minute = now.getMinutes();
    var nowMonth = nowMonth < 10 ? '0'+nowMonth :nowMonth
    var nowDate = nowDate < 10 ? '0'+nowDate :nowDate 
    var hour = hour < 10 ? '0'+hour :hour 
    var minute = minute < 10 ? '0'+minute :minute 
    showDateDom.attr('data-year', nowYear);
    showDateDom.attr('data-month', nowMonth);
    showDateDom.attr('data-date', nowDate);
    showDateDom.attr('data-hour', hour);
    showDateDom.attr('data-minute', minute);
    // 数据初始化
    function formatYear (nowYear) {
        var arr = [];
        for (var i = nowYear - 5; i <= nowYear + 5; i++) {
            arr.push({
                id: i + '',
                value: i //+ '年'
            });
        }
        return arr;
    }
    function formatMonth () {
        var arr = [];
        for (var i = 1; i <= 12; i++) {
            var i = i < 10 ? '0'+i :i 
            arr.push({
                id: i + '',
                value: i //+ '月'
            });
        }
        return arr;
    }
    function formatDate (count) {
        var arr = [];
        for (var i = 1; i <= count; i++) {
             var i = i < 10 ? '0'+i :i 
            arr.push({
                id: i + '',
                value: i //+ '日'
            });
        }
        return arr;
    }
    var yearData = function(callback) {
        callback(formatYear(nowYear))
    }
    var monthData = function (year, callback) {
        callback(formatMonth());
    };
    var dateData = function (year, month, callback) {
        var month = parseInt(month);
        if (/^(1|3|5|7|8|10|12)$/.test(month)) {
            callback(formatDate(31));
        }
        else if (/^(4|6|9|11)$/.test(month)) {
            callback(formatDate(30));
        }
        else if (/^2$/.test(month)) {
            if (year % 4 === 0 && year % 100 !==0 || year % 400 === 0) {
                callback(formatDate(29));
            }
            else {
                callback(formatDate(28));
            }
        }
        else {
            throw new Error('month is illegal');
        }
    };
    var hourData = function(one, two, three, callback) {
        var hours = [];
        for (var i = 0,len = 24; i < len; i++) {
             var i = i < 10 ? '0'+i :i 
            hours.push({
                id: i,
                value: i //+ '时'
            });
        }
        callback(hours);
    };
    var minuteData = function(one, two, three, four, callback) {
        var minutes = [];
        for (var i = 0, len = 60; i < len; i++) {
            var i = i < 10 ? '0'+i :i 
            minutes.push({
                id: i,
                value: i //+ '分'
            });
        }
        callback(minutes);
    };
    showDateDom.bind('click', function () {
        var oneLevelId = showDateDom.attr('data-year');
        var twoLevelId = showDateDom.attr('data-month');
        var threeLevelId = showDateDom.attr('data-date');
        var fourLevelId = showDateDom.attr('data-hour');
        var fiveLevelId = showDateDom.attr('data-minute');
        var iosSelect = new IosSelect(5, 
            [yearData, monthData, dateData, hourData, minuteData],
            {
                title: '时间选择',
                itemHeight: 35,
                itemShowCount: 9,
                oneLevelId: oneLevelId,
                twoLevelId: twoLevelId,
                threeLevelId: threeLevelId,
                fourLevelId: fourLevelId,
                fiveLevelId: fiveLevelId,
                callback: function (selectOneObj, selectTwoObj, selectThreeObj, selectFourObj, selectFiveObj) {
                    showDateDom.attr('data-year', selectOneObj.id);
                    showDateDom.attr('data-month', selectTwoObj.id);
                    showDateDom.attr('data-date', selectThreeObj.id);
                    showDateDom.attr('data-hour', selectFourObj.id);
                    showDateDom.attr('data-minute', selectFiveObj.id);
                    showDateDom.val(selectOneObj.value + '-' + selectTwoObj.value + '-' + selectThreeObj.value + ' ' + selectFourObj.value + ':' + selectFiveObj.value);
                }
        });
    });
}
